package cn.sangedon.review.data.spider;

import cn.sangedon.review.common.domain.data.SpiderMateData;
import cn.sangedon.review.common.service.data.StockDayInfoService;
import cn.sangedon.review.common.service.data.TradingDateService;
import cn.sangedon.review.data.constant.SpiderEnum;
import cn.sangedon.review.data.spider.impl.DropLimitSpider;
import cn.sangedon.review.data.spider.impl.HistoryStockInfoExcelSzSpider;
import cn.sangedon.review.data.spider.impl.RiseLimitSpider;
import cn.sangedon.review.data.spider.impl.SnowballQuotationSpider;
import cn.sangedon.review.data.spider.impl.StockOfDayExcelSzSpider;
import cn.sangedon.review.data.spider.impl.StockOfDayShSpider;
import cn.sangedon.review.data.spider.impl.StockOfDaySzSpider;
import cn.sangedon.review.data.spider.impl.TradeCalendarSpider;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class StockInfoSpiderFactory implements ISpiderFactory {
    @Autowired
    private StockDayInfoService stockDayInfoService;

    @Autowired
    private TradingDateService tradingDateService;

    @Autowired
    private StockOfDaySzSpider stockOfDaySzSpider;

    @Autowired
    private StockOfDayExcelSzSpider stockOfDayExcelSzSpider;

    @Autowired
    private HistoryStockInfoExcelSzSpider historyStockInfoExcelSzSpider;

    @Autowired
    private TradeCalendarSpider tradeCalendarSpider;

    @Autowired
    private StockOfDayShSpider stockOfDayShSpider;

    @Autowired
    private RiseLimitSpider riseLimitSpider;

    @Autowired
    private DropLimitSpider dropLimitSpider;

    @Autowired
    private SnowballQuotationSpider snowballQuotationSpider;

    @Override
    public ISpider createSpider(SpiderMateData spiderMateData) {
        if (spiderMateData == null) {
            log.info("爬虫元数据为空");
            return null;
        }
        AbstractStockInfoSpider spider = null;
        if (spiderMateData.getSpiderName().startsWith("SZD")) {
            spider = stockOfDaySzSpider;
        } else if (spiderMateData.getSpiderName().startsWith("SZE")) {
            spider = stockOfDayExcelSzSpider;
        } else if (spiderMateData.getSpiderName().startsWith("HSZE")) {
            spider = historyStockInfoExcelSzSpider;
        } else if (spiderMateData.getSpiderName().startsWith("ATD")) {
            spider = tradeCalendarSpider;
        } else if (spiderMateData.getSpiderName().startsWith("SHD")) {
            spider = stockOfDayShSpider;
        } else if (spiderMateData.getSpiderName().startsWith("DFCF_ZT")) {
            spider = riseLimitSpider;
        } else if (spiderMateData.getSpiderName().startsWith("DFCF_DT")) {
            spider = dropLimitSpider;
        } else if (spiderMateData.getSpiderName().equals(SpiderEnum.SNOWBALL_QUOTATION_INTIME.getName())) {
            spider = snowballQuotationSpider;
        }

        if (spider != null) {
            spider.setSpiderMateData(spiderMateData);
        }
        return spider;
    }
}
